<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="my" uri="/mytags" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>社会资助数据上报</title>
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/asserts/bootstrap-3.3.7-dist/css/bootstrap.min.css"/>
	
		<!-- js插件 -->
		<script src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
		<script src="${pageContext.request.contextPath}/asserts/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/asserts/bootstrapValidate/css/bootstrapValidator.min.css"/>
 	   <script src="${pageContext.request.contextPath}/asserts/bootstrapValidate/js/bootstrapValidator.min.js"></script>
	
	</head>
	<body>
			<!-- 内容展示区 -->
			<div >
					<!-- 导航 -->
					<ol class="breadcrumb">
						<li><i class="fa fa-comment"></i>社会资助数据上报</li>
					</ol>
					<div class="container-fluid">
						<!-- 	内容面板 -->
						<div class="panel panel-default">
			<!-- 				控制按钮
							<div class="panel-heading">
									<div class="btn-group">
										<button class="btn btn-primary" data-toggle="modal" data-target="#mymodal" ><span class="glyphicon glyphicon-pencil"></span>添加</button>
												<button class="btn btn-success"  data-toggle="modal" data-target="#mymodalimport"><span class="glyphicon glyphicon-import"></span>导入excel</button>
								    	<button class="btn btn-info" onclick="downTemplate()"><span class="glyphicon glyphicon-export"></span>导出excel模板</button>
								</div>
							</div>控制按钮  end -->
							<div class="panel-body">
								<form action="${pageContext.request.contextPath}/dataup/listsocietysub" method="post"  class="form-horizontal" >
								   <%--   <div class="form-group">
										<label class="control-label col-md-2">所在学校：</label>
										<div class="col-md-3">
											 <select name="schid" class="form-control">
											<option value="">请选择</option>
										 	<c:forEach var="school" items="${schoolList}">
										 		<option value="${school.schid}" <c:if test="${school.schid==schid}">selected="selected"</c:if>>${school.name}(${school.level})</option>
										 		
										 	</c:forEach>
											</select> 
										</div>
										
									</div> --%>
									 <div class="form-group">
									 	 <label class="control-label col-md-2">所属乡镇：</label>
											<div class="col-md-3">
												 		  <select id="zid" name="zid" class="form-control" onchange="changeZhen(this)">
															<option value="">请选择</option>
															<c:forEach var="xz" items="${xzList}">
																<option value="${xz.id}" <c:if test="${xz.id==dataUp.zid}">selected="selected"</c:if>>${xz.name}</option>
															</c:forEach>
														</select>
											</div>
										<label class="control-label col-md-2">所属学校(先选择乡镇)：</label>
										<div class="col-md-3">
											 <select id="schid" name="schid" class="form-control">
												<option value="">请选择</option>
												  <c:forEach var="school" items="${schoolListByZid}">
										 		   <option value="${school.schid}" <c:if test="${school.schid==dataUp.schid}">selected="selected"</c:if>>${school.name}(${school.level})</option>
										 		
										 	      </c:forEach>
											</select> 
										</div>
										 
									</div>
									 <div class="form-group">
								<%-- 		<label class="control-label col-md-2">上报状态：</label>
										<div class="col-md-3">
											 <select name="status" class="form-control">
											  	<option value="">请选择</option>
											  		<option value="1" <c:if test="${dataUp.status==1}">selected</c:if>>初稿</option>
											  		<option value="2" <c:if test="${dataUp.status==2}">selected</c:if>>镇级别审核中</option>
											  		<option value="3" <c:if test="${dataUp.status==3}">selected</c:if>>县级别审核中</option>
											  	 
											  </select>
										</div> --%>
										<label class="control-label col-md-2">资助名称：</label>
										<div class="col-md-3">
										 
											  	<input type="text" name="project" placeholder="请输入资助名称" class="form-control"  />
										</div>
										<div class="col-md-2">
												<button class="btn btn-default" type="reset">重置</button>
												<button class="btn btn-success" type="submit">查询</button>
										</div>
									 </div>
								</form>
											<c:if test="${user.roleid==3 or user.roleid==4 or user.roleid==2}">
									<div class="col-md-6">
									<table id="listtable" class="table table-bordered table-striped table-condensed table-hover">
										<tr>
											<c:if test="${user.roleid==2}">
												<th colspan="5" style="text-align:center">按项目该镇人数金额总统计</th>
											</c:if>
											<c:if test="${user.roleid!=2}">
												<th colspan="5" style="text-align:center">按项目该县人数金额总统计</th>
											</c:if>
										</tr>
										<tr>
											<th width="3%">序号</th>
											<th width="17%">受助项目</th>
											<th width="8%">总人数</th>
											<th width="10%">总金额</th>
											<th width="10%">状态</th>
										</tr>
										<c:forEach items="${projectList}" var="pro"  varStatus="vs">
										<tr>
												<td>${vs.index+1}</td>
												<td>${pro.project}</td>
												<td>${pro.cts}</td>
												<td>${pro.amounts}</td>
												<td>
													<c:if test="${pro.status==2}">镇级别审核中</c:if>
													<c:if test="${pro.status==3}">县级别审核中</c:if>
 											   </td>
											 
										</tr>
										</c:forEach>
									</table>
									</div>
								</c:if>
								
								<table id="listtable" class="table table-bordered table-striped table-condensed table-hover">
									<tr>
										<th width="3%">序号</th>
										<th width="8%">学校</th>
										<th width="10%">上报项目</th>
										<th width="10%">资助名称</th>
 										<th width="5%">总人数</th>
										<th width="8%">金额(元)</th>
										<th width="5%">状态</th>
										<th width="20%">操作</th>
									</tr>
									<!-- 数据绑定 -->
									<c:forEach items="${pageInfo.list}" var="dataup" varStatus="vs">
										<tr>
 											<td>${vs.index+1}</td>
											<td>${dataup.schoolname}</td>
											<td>社会资助</td>
											<td>${dataup.project}</td>
											<td>${dataup.cts}</td>
											<td>${dataup.amounts}</td>
											<td>
												<c:if test="${dataup.status==1}">初稿</c:if>
												<c:if test="${dataup.status==2}">镇级别审核中</c:if>
												<c:if test="${dataup.status==3}">县级别审核中</c:if>
<%-- 											<c:if test="${dataup.status==4}">归档</c:if>
 --%>											</td>
											<td>
												 
												 <button type="button" class="btn btn-primary" onclick="dataUp(${dataup.schid},'${dataup.project}',${dataup.status})"> 
												 	<span class="glyphicon glyphicon-upload"></span> 
												 		<c:if test="${dataup.status==3}">数据归档</c:if>
												 		<c:if test="${dataup.status!=3}">数据上报</c:if>
												 	</button>
												  <button type="button" class="btn btn-danger" onclick="dataDown(${dataup.schid},'${dataup.project}',${dataup.status})"> 
												 	<span class="glyphicon glyphicon-file"></span> 撤销上报</button>
											</td>
										</tr>
									</c:forEach>
									<!-- 	数据绑定 end -->
								</table>
								<!-- 	分页 -->
								<my:page prePage="${pageInfo.prePage}" nextPage="${pageInfo.nextPage}"
				 url="${pageContext.request.contextPath}/dataup/listsocietysub?n=1&x=1" totalPage="${pageInfo.pages }" currentPage="${pageInfo.pageNum}"/>
									 
							</div>
						</div><!-- 内容面板 end -->
					</div>
			</div><!-- 	内容展示区 end-->
</body>
<script type="text/javascript">
 

function changeZhen(obj){
	 //ajax   根据镇id 查询 它学校表中的 数据 
	if(obj.value!=''){
		  $.ajax({
				url : '../school/getSchoolByZid?zid='+obj.value,
				type : "get",
				dataType : "json",
				success : function(data) {
					 
					if(data!=null){
						$("#schid option:gt(0)").remove();
						for(var i=0;i<data.length;i++){
							var opt = "<option value='"+data[i].schid+"'>"+data[i].name+"("+data[i].level+")</optoin>";
							$("#schid").append(opt);
						}
					} 
				},
				error : function(xhr) {
					 
				}
			});
	}else{
		$("#schid option:gt(0)").remove();
	}
}
  function dataUp(schid,project,status){
	 
	  $.ajax({
			type:"post",
			url:"upsocietysub",
			data:"schid="+schid+"&project="+project+"&status="+status,
			dataType:"JSON",
			success:function(data){
			 
			      if(data.status==200){
			    	  //登录成功
			    	  alert(data.msg);
			    	  location.href="listsocietysub";
			      }else{
			    	 alert(data.msg);
			      }
			}
			
		});
  }
  
  function dataDown(schid,project,status){
	  if(status==1){
		  alert("初稿状态的数据不能撤销上报");
		  return;
	  } 
	  $.ajax({
			type:"post",
			url:"downsocietysub",
			data:"schid="+schid+"&project="+project+"&status="+status,
			dataType:"JSON",
			success:function(data){
			 
			      if(data.status==200){
			    	  //登录成功
			    	  alert(data.msg);
			    	  location.href="listsocietysub";
			      }else{
			    	 alert(data.msg);
			      }
			}
			
		});
  }
  /* document.documentElement.style.overflowY = 'hidden'; */
</script>
</html>